import request from '@src/utils/request';
import { URL } from '@src/configs/constant';

// 首页数据统计
export async function getDecimal(params) {
  const { ChainId = '' } = params;
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'Decimal',
      ChainId,
    },
  });
  return res;
}

// 最新合约列表
export async function getLatestContract() {
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetLatestContract',
      Number: 10,
    },
  });
  return res;
}

// 最新链列表
export async function getLatestChain() {
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetLatestChain',
      Number: 10,
    },
  });
  return res;
}

// 最新区块列表
export async function getLatestBlockList(params) {
  const { ChainId = '' } = params;
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetLatestBlockList',
      ChainId,
      Number: 6,
    },
  });
  return res;
}

// 最新交易列表
export async function getLatestTxList(params) {
  const { ChainId = '' } = params;
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetLatestTxList',
      ChainId,
      Number: 6,
    },
  });
  return res;
}

// 节点信息·查看节点列表
export async function getNodeList(params) {
  const { Offset = 0, Limit = 5, ChainId = '' } = params;
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetNodeList',
      ChainId,
      Offset,
      Limit,
    },
  });
  return res;
}

// 首页查询
export async function getDetail(params) {
  const { Id = '', ChainId = '' } = params;
  const res = await request({
    url: URL,
    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
    params: {
      cmb: 'GetDetail',
      Id,
      ChainId,
    },
  });
  return res;
}
